home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7519 < prev    next >
Encoding:
Text File  |  1996-08-05  |  8.1 KB  |  249 lines

  1. Path: news.ucdavis.edu!usenet
  2. From: "Harry H. Cheng" <hhcheng@ucdavis.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: CH Language Environment
  5. Date: Mon, 26 Feb 1996 17:29:02 -0800
  6. Organization: University of California, Davis
  7. Message-ID: <31325E5E.1667@ucdavis.edu>
  8. NNTP-Posting-Host: dragon.engr.ucdavis.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.3 sun4m)
  13. Content-Disposition: inline; filename="l4"
  14.  
  15.  
  16. I would like to announce that the CH language environment
  17. is available to users of SunOS, Solaris, LynxOS.
  18. CH is designed as a superset of C interpreter.
  19. It can be used for Unix shell programming, WWW Common
  20. Gateway Interface, WWW Common Client Interface, ...
  21. The differences between CH and C are highlighted as follows:
  22.  
  23.  
  24. EXTENSIONS TO C (some features are currently debated by 
  25. C Standard Committee ANSI/X3J11 and ISO/SC22/WG14 as new 
  26. features
  27. of the next version of C standard called C9x)
  28.  
  29. (1) CH is an interpretive implementation of ANSI C as Unix shell.
  30.     It can be used as login shell. Here are some differences between 
  31.     CH and C shells.
  32.  
  33.           CH shell                           C shell
  34.     _path = "/usr/bin /bin"            set path = (/usr/bin /bin)
  35.     printf("%s\n", getenv("PATH"))
  36.     putenv("PATH=/usr/bin /bin")       setenv PATH "/usr/bin /bin" 
  37.     printf("%s\n", getenv("PATH"))     echo $PATH
  38.     echo $(getenv("PATH"))             echo $PATH
  39.     printf("%s\n", _path)              echo $path
  40.     remenv("PATH")                     unsetenv PATH
  41.     emvar("_path")                     unset path 
  42.     int i = 90                         set i =90
  43.     i = 91                             set i =91
  44.     string hostnam =`hostname`         set hostnam =`hostname`
  45.     alias("rm", "rm -i")               alias rm 'rm -r' 
  46.     unalias("rm")                      unalias rm 
  47.     _histsize = 100                    history = 100
  48.     history                            history 
  49.     ls ~ *                             ls ~ *
  50.     ls > output                        ls > output
  51.     ls $(getenv("PATH"))               ls $PATH
  52.     ls $_path                          ls $path
  53.     $l -agl                            !l -agl
  54.     $3                                 !3 
  55.     $-1                                !-1
  56.     $$                                 !!
  57.     more .chshrc .chlogin .chlogout    more .cshrc .login .logout
  58.     more .rchshrc .chlogin .chlogout   more .cshrc .login .logout
  59.     more .schshrc .chlogin .chlogout   more .cshrc .login .logout
  60.  
  61.     restricted shell                    restricted shell
  62.  
  63.  
  64. There is safe shell in CH for internet computing.
  65. In addition to restrictions imposed by conventional restricted shell,
  66. the following features are disallowed for across-network internet computing
  67. in safe CH shell.
  68.     (a) declaration of pointers.
  69.     (b) built-in functions remove(), rename(), unlink(), open(), and fopen().
  70. The restrictions above are enforced after .schshrc is interpreted.
  71. If CH is invoked with option -S, options -r and -f will be ignored.
  72.  
  73. (2) Complex is a built-in data type 
  74. handled similar to that in Fortran.
  75. For example,
  76.       float f=90;
  77.       complex z=complex(1,2);
  78.       z = 2*f*z*sin(z)*atan(z);
  79.  
  80. (3) String is a first-class object for across-network computing.
  81. For example,
  82.       string s, a[3];
  83.       s = "great string"
  84.       strcpy(a[0], s);
  85.       strcat(s, s);
  86.       printf("s = %s\n", s);
  87.  
  88. (4) Functions can be nested and recursively nested
  89. similar to implementation in GNU gcc.
  90. For example,
  91.       int func1() {
  92.          void func2() {
  93.             int func3() { ...}
  94.          }
  95.          ...
  96.          func2();
  97.       }  
  98.  
  99. (5) Arrays of variable length. They include
  100. deferred-shape arrays, assumed-shape arrays, and pointer
  101. to assumed-shape arrays.
  102. The following example will clarify the concepts of these
  103. various array definitions.
  104.   void funct(int a[:][:], (*b)[:], c[], n, m){
  105.   /* a: assumed-shape array */
  106.   /* b: pointer to array of assumed-shape */
  107.   /* c: incomplete array completed by function call */
  108.     int d[4][5];     /* d: fixed-length array */
  109.     int e[n][m];     /* e: deferred-shape array */
  110.     int (*f)[:];     /* f: pointer to array of assumed-shape */
  111.     extern int g[];  /* g: incomplete array completed by external linkage */
  112.     int h[] = {1,2}; /* h: incomplete array completed by initialization */
  113.     e[1][2] = a[2][3];
  114.   }
  115.   int A[3][4], B[5][6], C[3];
  116.   funct(A, B, C, 10, 20);
  117.   funct(B, A, C, 85, 85);
  118.  
  119. (6) Arrays of adjustable range.
  120. The range of subscript for an index of array can be adjusted.
  121. For example,
  122.   int a[1:10], b[-5:5], c[0:10][1:10], d[10][1:10], e[n:m], f[n1:m1][1:m2];
  123.   extern int a[1:], b[-5:], c[0:][1:10];
  124.   int funct(int a[1:], int b[1:10], int c[1:][3], int d[1:10][0:20]);
  125.   a[10] = a[1]+2; /* OK */
  126.   a[0] = 90;      /* Error: index out of range */
  127.  
  128. (7) Computational array.
  129. An array qualified by type qualifier {array} is
  130. called  computational array.
  131. A computational array is treated as  a first-class object
  132. as in Fortran 90. For example,
  133.        array float a[10][10], b[10][10];
  134.        a += b+inverse(a)*transpose(a)+sin(a);
  135.  
  136. (8) Fortran arrays.
  137. An array qualified by type qualifier {fortran} is
  138. called fortran-style array.
  139. Unlike a C array,
  140. elements of a fortran-style array are stored column-wise.
  141. For example,
  142.   fortran array float A[10][10], B[10][10];
  143.   fortran float a[10][10], b[10][10];
  144.   float *p;   
  145.   p = &a[0][0];
  146.   *(p+1) = 90; /* <==> a[1][0] = 90; not a[0][1] = 90 */
  147.   funct((float [10])&A[5][10]); /* pass column 6 to function funct() */
  148.  
  149. Fortran code can be ported to CH easily.
  150. We have ported over 10,000 lines of LAPACK package to CH.
  151.  
  152.  
  153. (9)Reference for internet computing.
  154. Reference for basic data types char, short, int,
  155. float, double, as well as data types qualified
  156. by signed, unsigned, long, complex, and dual
  157. can be declared.
  158. Functions can be called by reference.
  159. The same syntax in C++ is used in CH.
  160. For example,
  161.   int i;
  162.   int &j = i;
  163.   int A, B;
  164.   void swap(int &n, int &m); /* the same as in C++ */
  165.   swap(A, B);                /* pass by reference as in Fortran */
  166.  
  167. (10) Many high-level toolboxes and function files such as
  168.     plotxy(), plotxyz(), plotxyf(), plotxyzf() for plotting.
  169.  
  170.  
  171.  
  172. MISSING C FEATURES
  173. (1) struct/union/bit-fields.
  174. (2) pointer to functions.
  175. These features will be implemented in CH in the future.
  176.  
  177.  
  178. WHY CH?
  179.  
  180. (1) Like Java, CH can be used for across network
  181. world-wide distributed computing.
  182. It can be used for WWW Common Gateway Interface (CGI), 
  183. WWW Common Client Interface (CCI).
  184. Toolboxes for CGI and CCI are available.
  185. They are easy to use. Examples of World-Wide
  186. Distributed Computing in the CH language environment
  187. can be found on the WWW at the URL address
  188.    http://iel.ucdavis.edu/CH/tutor/wwdc/
  189.  
  190. (2) If you use common set of C and CH, 
  191. your CH code can be compiled in native C compiler.
  192. Your C programs without structure and pointer to functions
  193. can run in the CH language environment
  194. without compilation. 
  195. Normally, CH is 1.xx% to 100% slower than compiled C code, 
  196. depending on applications. But,
  197. if your code takes advantage of high-level features of CH,
  198. such as inverse(A) for computing inverse of matrix A,
  199. CH code can be 
  200. just as fast as your C program.
  201.  
  202.  
  203. (3) It can be used for rapid prototyping of real-time applications.
  204. It can be used to test your device drivers and hardware setup.
  205.  
  206. (4) Like Basic and C shell, CH is interactive.
  207. If you are not sure a C feature, you can verify it
  208. easily under the CH language environment.
  209. If you are a student learning C, 
  210. you may find this interactive feature is handy.
  211. For example,
  212.  
  213.    prompt> hello.c
  214.    Hello, world!
  215.    (execute hello.c program without compilation)
  216.    prompt> int i, *p;
  217.    prompt> p = &i; 
  218.    prompt> *p = 90;
  219.    prompt> printf("i = %d\n", i);
  220.    i = 90
  221.    prompt> int **p2
  222.    prompt> p2 = &p
  223.    prompt> printf("**p2 = %d\n", **p2)
  224.    **p2 = 90
  225.    prompt> ls * > junkfile
  226.    (all file names go to junkfile)
  227.    prompt> i**p
  228.    8100
  229.    prompt> array a[2][3]
  230.    prompt> a = 2
  231.    prompt> a
  232.    5 5 5 
  233.    5 5 5
  234.    prompt> 2*transpose(a)
  235.    10 10 
  236.    10 10 
  237.    10 10 
  238.    prompt>
  239.  
  240.  
  241. CH runs on SunOS, Solaris, MVME167/LynxOS 2.2.1.
  242. It is available free for downloading
  243. on the WWW at the URL address 
  244.    http://iel.ucdavis.edu/CH/
  245.  
  246.  
  247. Harry Cheng
  248.  
  249.